<script lang="ts" setup>
import { ref } from "vue";
import { hope } from "../../@types/hope";
import LoginPhone from './Login-phone.vue'
import LoginPwd from './Login-pwd.vue'
import Register from './Register.vue'
import Reset from './Reset.vue'

type TypeInfo = 'login-phone' | 'login-pwd' | 'register' | 'reset';
const type = ref('login-pwd' as TypeInfo)

function onClose(): void {
  hope.destroyDiv("login");
}

function onChangeType(value: TypeInfo = 'login-pwd'): void {
  type.value = value;
}
</script>
<template>
  <div class="mask" @click="onClose"></div>
  <div class="card flex">
    <!-- <div class="brand"></div> -->
    <div class="form flex-c">
      <div class="top">
        <icon-close size="20" class="icon" @click="onClose" />
      </div>
      <div class="body">
        <LoginPhone v-if="type === 'login-phone'" @close="onClose" @change="onChangeType" />
        <LoginPwd v-else-if="type === 'login-pwd'" @close="onClose" @change="onChangeType" />
        <Register v-else-if="type === 'register'" @close="onClose" />
        <Reset v-else-if="type === 'reset'" @close="onClose" @change="onChangeType" />
      </div>
      <div class="bottom">
        <p v-if="type === 'login-phone'">
          <span style="font-size: 13px">还没有账号？</span>
          <a-link theme="primary" @click="onChangeType('register')"> 立即注册 </a-link>
        </p>
        <p v-else-if="type === 'login-pwd'">
          <span style="font-size: 13px">还没有账号？</span>
          <a-link theme="primary" @click="onChangeType('register')"> 立即注册 </a-link>
        </p>
        <p v-else-if="type === 'register'">
          <span style="font-size: 13px">已有账号？</span>
          <a-link theme="primary" @click="onChangeType('login-pwd')"> 立即登录 </a-link>
        </p>
        <a-link theme="primary" @click="onChangeType('login-pwd')" v-else> 返回登录 </a-link>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.mask {
  position: fixed;
  top: 0;
  left: 0;
  background: var(--color-neutral-10);
  opacity: 0.3;
  width: 100vw;
  height: 100vh;
  z-index: 9;
}

.card {
  width: 470px;
  max-width: 96vw;
  background: var(--color-bg-1);
  border-radius: 20px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9;
  overflow: hidden;

  .brand {
    height: 100%;
    flex: 1;
    // background: url("@/assets/login-bg.webp") no-repeat;
    background-size: 100% 100%;
  }

  .form {
    width: 100%;
    height: 100%;
    flex: 1;
    justify-content: space-between;

    .top {
      width: 100%;
      text-align: right;
      padding: 42px 38px 0;

      .icon {
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }

    .body {
      width: 100%;
      padding-bottom: 20px;
    }

    .bottom {
      width: 100%;
      height: 64px;
      background: var(--color-neutral-3);
      border-radius: 0px 0px 20px 0px;
      line-height: 64px;
      font-size: 18px;

      font-weight: 500;
      color: var(--color-neutral-10);
      padding-left: 20px;
      cursor: pointer;
    }
  }
}
</style> 